﻿using UnityEditor;
using UnityEngine;
using System.Collections;

[CustomEditor(typeof(PUEXPlaySoundHandle))]
public class PUEXPlaySoundHandleEditor : Editor {
	
	public override void OnInspectorGUI ()
	{
		serializedObject.Update ();

		var handleNameProperty = serializedObject.FindProperty ("handleName");
		var eventTypeProperty = serializedObject.FindProperty ("eventType");
		var eventNameProperty = serializedObject.FindProperty ("eventName");
		var audioClipProperty = serializedObject.FindProperty ("audioClip");
		var loopUntilEndProperty = serializedObject.FindProperty ("loopUntilEnd");
		var pitchProperty = serializedObject.FindProperty ("pitch");
		var panProperty = serializedObject.FindProperty ("pan");
		var gainProperty = serializedObject.FindProperty ("gain");

		EditorGUILayout.PropertyField (handleNameProperty);
		
		EditorGUILayout.PropertyField (eventTypeProperty, new GUIContent("If"));
		var newEventType = (PUEXHandle.EvnetType)eventTypeProperty.enumValueIndex;
		switch (newEventType) {
		case PUEXHandle.EvnetType.ET_NOTIFY_EVENT: {
			EditorGUILayout.PropertyField (eventNameProperty, new GUIContent("Event Name"));
			break;
		}
		default:
			break;
		}

		EditorGUILayout.PropertyField (audioClipProperty, new GUIContent("Play"));
		if (newEventType == PUEXHandle.EvnetType.ET_EMITTER_START) {
			EditorGUILayout.PropertyField (loopUntilEndProperty);
		}
		EditorGUILayout.PropertyField (pitchProperty, new GUIContent("Frequency", "default: 1.0 range: 0.0 ~ 3.0"));
		EditorGUILayout.PropertyField (panProperty, new GUIContent("Stereo", "default: 0.0 range: -1.0 ~ 1.0"));
		EditorGUILayout.PropertyField (gainProperty, new GUIContent("Volume", "default: 1.0 range: 0.0 ~ 1.0"));

		serializedObject.ApplyModifiedProperties ();
	}

}
